package com.conrtoller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
//大傻逼
@Controller
@RequestMapping("/testSession")
public class SessionController {
    //放入session
    @RequestMapping("/put")
    @ResponseBody
    public String test1(@RequestParam String userName, HttpSession session){
    session.setAttribute("userName",userName);
    return userName;
    }

    //获取session
    @RequestMapping("/get")
    @ResponseBody
    public String test2(HttpSession session){
        String attribute = (String)session.getAttribute("userName");
        System.out.println(attribute);
        return attribute;
    }
}
